package com.example.ui.activity;

import android.content.Intent;

import com.example.administrator.sharker_demo.R;
import com.example.models.FirstHand;
import com.example.models.data.ResponseData;
import com.example.network.RetrofitHelper;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 董建业  时间:2017/4/10.
 * 首次握手使用界面
 */

public class SplashActivity extends TransitionActivity{

    @Override
    public int getlayoutid() {
        return R.layout.activity_splash;
    }

    @Override
    protected void requestdata() {

        RetrofitHelper.getUserApi().firstHand(RetrofitHelper.getParams(RetrofitHelper.createParams()))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ResponseData<FirstHand>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ResponseData<FirstHand> firstHandResponseData) {
                        FirstHand.save(firstHandResponseData.data);
                        gethost();
                    }
                });
    }

    public void gethost() {
        RetrofitHelper.getUserApi().getHost(RetrofitHelper.getParams(RetrofitHelper.createParams()))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ResponseData<FirstHand>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ResponseData<FirstHand> firstHandResponseData) {
                        FirstHand.saveHost(firstHandResponseData.data);
                        startActivity(new Intent(SplashActivity.this,MainActivity.class));
                        finish();
                    }
                });
    }
}
